<template>
  <layoutBlock >
    <div class="content">
      <div class="fliter-list">
        <RadioGroup v-model="createdDateType"  type="button" button-style="solid" @on-change="handleCreatedDateType">
          <Radio   :label="item.value"  v-for="item in statusList"  >{{item.name}}</Radio>
        </RadioGroup>
        <DatePicker class="data-picker" @on-change="changeData" v-if="dateShow" v-model="condition.createdStartDate" type="date" placeholder="请选择时间" style="width: 200px"></DatePicker>
      </div>

      <Table :loading="loading" @on-selection-change="selectList" border class="mt20" ref="selection" :columns="columns2" :data="data1">
        <template slot-scope="{ row, index }" slot="handledStatus" >
          <Tag color="#87d068" v-if="row.handledStatus == '11'"> 已处理 </Tag>
          <Tag color="#cd201f" v-else> 未处理 </Tag>
        </template>
        <template slot-scope="{ row }" slot="action">
          <a href="#" @click="lookDetail(row)">详情</a>
        </template>
      </Table>
      <div class="disflex mt30">
        <Page :total="total" v-if="total>condition.limit"  :current="condition.start" show-elevator @on-change="changepage"></Page>
      </div>
    </div>
    <Modal  footer-hide  width="800"
          v-model="showDetailModel"
          title="详情">
        <faultDetail v-if="showDetailModel" v-bind:faultId="faultId"></faultDetail>
      </Modal>
  </layoutBlock>
</template>
<script>
import {faultList} from '@/api/fault';
import faultDetail from '../../components/alarmFault/faultDetail';
import tool from "../../libs/tool";
import moment from 'moment'
import base from '@/mixins/base';
export default {
  mixins: [base],
  components: { faultDetail },
  data () {
    return {
      showDetailModel:false,
      loading:false,
      total:0,//总条数
      roleId:'',
      editorData:{},
      title:'编辑',
      createdDateType:0,
      dateShow:false,
      statusList:[
        {name:'全部',value:0},
        {name:'今天',value:1},
        {name:'昨天',value:2},
        {name:'近7天',value:3},
        {name:'近30天',value:4},
        {name:'选择日期',value:5},
      ],
      condition:{//头部筛选传参
        createdStartDate:'',
        limit:10,
        start:1
      },
      columns2: [
        {
          title: '上报时间',
          key: 'createdAt'
        },
        {
          title: '上报人员',
          key: 'createdName'
        },
        {
          title: '故障类型',
          key: 'faultType'
        },
        {
          title: '内容描述',
          key: 'content',
          ellipsis:true
        },
        {
          title: "查看",
          width: 70,
          slot: "action",
        },
        {
          title: '处理状态',
          slot: 'handledStatus',
          align:'center'
        },
      ],
      data1: [],
      detail:'',
      ids:'',
      isAdd:true,
      noShow:false,
      userId:'',
      isShowUser:false,
      selectlist:[],
      orgList:[],
      faultId:''
    }
  },
  created(){
    this.getData();
  },
  methods: {
    handleCreatedDateType(value,e){
       if(value==5){
         this.dateShow=true
       }else if(value==0){
         this.dateShow=false;
         this.condition.createdStartDate='';
         this.getData();
       }else{
         this.dateShow=false;
         this.condition.createdStartDate=this.getTime(value);
         this.getData();
       }
    },
    changeData(){
      this.getData();
    },
    getTime(label){
      switch (label){
        case 1:
          return moment().format('YYYY-MM-DD');
        case 2:
          return moment().subtract(1, 'days').format('YYYY-MM-DD');
        case 3:
          return moment().subtract(7, 'days').format('YYYY-MM-DD');
        case 4:
          return moment().subtract(30, 'days').format('YYYY-MM-DD');
      }
    },
    selectList(value){
      this.condition.start=1;
      this.selectlist=value
    },
   //查看详情
    lookDetail(row) {
      this.faultId = row.id;
      this.showDetailModel = true;
    },
    success(){
      this.getData();
      this.isShow=false;
      this.isShow03=false;
    },
    //获取列表
    async getData(){
      this.loading=true;
      let {limit,start}  = this.condition;
      let parms=this.createdDateType==5?{limit,start,createdDate:moment(this.condition.createdStartDate).format('YYYY-MM-DD'),porgIds:this.orgIds}:{...this.condition ,porgIds:this.orgIds}
      let  res = !this.orgIds?this.defaultListData:await  faultList(parms);
      this.loading=false;
      this.data1= _.get(res,'data.records') ||[];
      this.total=_.get(res,'data.total')||0;
    },
    //分页projectType
    changepage(page){
      this.condition.start = page
      this.getData()
    },
    cancel(){},
  }
}
</script>

<style scoped lang="less">
.fliter-list{
  display: flex;
  .data-picker{
    margin-left: 20px;
  }
}
</style>
